<template>
  <div id="table_container">
    <div id="content">
      <div class="content_title">
        <el-image :src="Logo"></el-image>
        <!--        <img class="logo" src="@/assets/logo.jpg" alt="logo"/>-->
        <span>儿童青少年近视自动筛查防控平台</span>
      </div>
      <div class="content_form">
        <el-form :model="loginForm" :rules="rules" ref="loginForm" label-width="50px" size="medium">
          <el-form-item label="账号" prop="username">
            <el-input size="medium" v-model="loginForm.username" placeholder="请输入账号"
                      prefix-icon="el-icon-user-solid"></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input size="medium" v-model="loginForm.password" @keyup.enter.native="submitForm()" type="password"
                      placeholder="请输入密码"
                      prefix-icon="el-icon-s-promotion"></el-input>
          </el-form-item>
          <el-button size="medium" type="primary" @click="submitForm()" class="submit_btn">登 录</el-button>
        </el-form>
      </div>
      <div class="content_footer">
        <!--        <p class="wxtip">温馨提示：</p>-->
        <p class="tip">——眼睛是心灵之窗——</p>
      </div>
    </div>
    <div id="footer">
      <p>————版权所有————</p>
    </div>

  </div>
</template>

<script>
import Logo from '@/assets/logo.png'
import {login} from "@/api";

export default {
  name: "Login",
  data() {
    return {
      Logo: Logo,
      loginForm: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          {required: true, message: '请输入用户名', trigger: 'blur'},
          {min: 2, max: 16, message: '长度在 2 到 16 个字符', trigger: 'blur'}
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'}
        ],
      }
    }
  },
  methods: {
    submitForm() {
      this.$refs['loginForm'].validate((valid) => {
        if (valid) {
          let userinfo = this.loginForm;
          // console.log('登录了')
          login(userinfo).then(res => {
            let data = res.data
            localStorage.setItem('token', data.access)
            localStorage.setItem('refresh', data.refresh)
            this.$router.push('/')
            // this.$router.go(0)
            // this.$store.dispatch('initLeftMenu'); //设置左边菜单始终为展开状态
          })
        }
      });
    }
  }
}
</script>

<style scoped>


#table_container {
  background: #f0f2f5 url('./backgroundImage.jpg') no-repeat;
  background-size: cover;
  position: absolute;
  width: 100%;
  height: 100%;
}


#content {
  position: relative;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%); /* IE 9 */
  -moz-transform: translate(-50%, -50%); /* Firefox */
  -webkit-transform: translate(-50%, -50%); /* Safari 和 Chrome */
  -o-transform: translate(-50%, -50%); /* Opera */
  width: 450px;
  background-color: rgba(255, 255, 255, 0.5);
  padding: 30px 0;
  border-radius: 10px;
  color: rgba(0, 0, 0, 0.65);
}

#content .content_title {
  font-size: 26px;
  font-weight: bold;
  text-align: center;
  margin-bottom: 40px;
}

#content .content_title .el-image {
  width: 40px;
  vertical-align: middle;
  border-radius: 50%;
}

#content .content_title span {
  vertical-align: middle;
  margin-left: 10px;
}

/*      表单   start    */
#content .content_form {
  padding: 0 60px;
}

#content .submit_btn {
  margin-top: 10px;
  width: 100%;
  font-size: 16px;
}

#content .content_footer {
  font-size: 16px;
  color: #4cbb15;
  text-align: center;
  margin-top: 40px;
  margin-bottom: 20px;
}

#content .tip {

}


/*        footer         */

#footer {
  position: absolute;
  bottom: 50px;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%); /* IE 9 */
  -moz-transform: translate(-50%, -50%); /* Firefox */
  -webkit-transform: translate(-50%, -50%); /* Safari 和 Chrome */
  -o-transform: translate(-50%, -50%); /* Opera */
}
</style>